/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.krazevina.kar;

import com.sun.lwuit.Button;
import com.sun.lwuit.Command;
import com.sun.lwuit.Container;
import com.sun.lwuit.Form;
import com.sun.lwuit.Image;
import com.sun.lwuit.Label;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.plaf.Style;
import java.io.IOException;


/**
 *
 * @author XXX
 */
public class FirstForm extends Form{
    Label lbltop;
    Button bt1,bt2,bt3,bt4;
    Image backbtn,btn1,btn2,btn3,btn4,topfirst;
    public static Image backgr;
    Container cbt1,cbt2,cbt3,cbt4;
    Command exit,about;
    
    public FirstForm(){
        try {
            topfirst = Image.createImage("/topfirst.png");
            backgr = Image.createImage("/backgr.png");
            backbtn = Image.createImage("/btn.png");
            btn1 = Image.createImage("/ico1.png");
            btn2 = Image.createImage("/ico2.png");
            btn3 = Image.createImage("/ico3.png");
            btn4 = Image.createImage("/ico4.png");
            
            cbt1 = new Container(new BoxLayout(BoxLayout.X_AXIS));
            cbt2 = new Container(new BoxLayout(BoxLayout.X_AXIS));
            cbt3 = new Container(new BoxLayout(BoxLayout.X_AXIS));
            cbt4 = new Container(new BoxLayout(BoxLayout.X_AXIS));
            
            setConStyle(cbt1);
            setConStyle(cbt2);
            setConStyle(cbt3);
            setConStyle(cbt4);
            Label l1,l2,l3,l4;
            l1 = new Label(btn1);
            S.setTrans(l1);
            l2 = new Label(btn2);
            S.setTrans(l2);
            l3 = new Label(btn3);
            S.setTrans(l3);
            l4 = new Label(btn4);
            S.setTrans(l4);
            bt1 = new Button("Danh sách ca sĩ");
            bt2 = new Button("Danh sách bài hát");
            bt3 = new Button("Danh sách ưa thích");
            bt4 = new Button("Tìm kiếm");
            S.setTransF(bt1);S.setTransF(bt2);
            S.setTransF(bt3);S.setTransF(bt4);
            
            bt2.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    MainForm.searchType = 0;
                    MainForm.headerSearch = false;
                    MainForm.lastSearch = "a";
                    Main.getInstance().showMain();
                }
            });
            bt1.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    MainForm.searchType = 5;
                    MainForm.headerSearch = false;
                    MainForm.lastSearch = "c";
                    Main.getInstance().showMain();
                }
            });
            bt3.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    MainForm.searchType = 4;
                    MainForm.headerSearch = false;
                    MainForm.lastSearch = "";
                    Main.getInstance().showMain();
                }
            });
            bt4.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    MainForm.headerSearch = true;
                    Main.getInstance().showMain();
                }
            });
            cbt1.addComponent(l1);cbt1.addComponent(bt1);
            cbt2.addComponent(l2);cbt2.addComponent(bt2);
            cbt3.addComponent(l3);cbt3.addComponent(bt3);
            cbt4.addComponent(l4);cbt4.addComponent(bt4);
            
            lbltop = new Label("My Karaoke List");
            setTopstyle();
            
            
            getStyle().setBgImage(backgr);
            getStyle().setBgTransparency(255);
            getStyle().setAlignment(Container.CENTER);
            addComponent(lbltop);
            addComponent(cbt1);
            addComponent(cbt2);
            addComponent(cbt3);
            addComponent(cbt4);
            addcmd();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
    void addcmd(){
        try {
            exit = new Command("Thoát", Image.createImage("/btnthoat.png"));
            about = new Command("Thông tin", Image.createImage("/btntt.png"));
            addCommand(about);
            addCommand(exit);
            Style s = new Style();
            s.setMargin(0,0,0,0);
            s.setPadding(0,0,0,0);
            s.setBorder(null);
            getSoftButton(0).setUnselectedStyle(s);
            getSoftButton(0).setPressedStyle(s);
            getSoftButton(0).setSelectedStyle(s);
            getSoftButton(0).setFocusable(false);
            getSoftButton(1).setUnselectedStyle(s);
            getSoftButton(1).setPressedStyle(s);
            getSoftButton(1).setSelectedStyle(s);
            getSoftButton(1).setFocusable(false);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    protected void actionCommand(Command cmd) {
        super.actionCommand(cmd);
        if(cmd.equals(exit)){
            Main.getInstance().notifyDestroyed();
        }else{
            Main.getInstance().showAbout();
        }
    }
    
    final void setTopstyle(){
        Style s = new Style();
        s.setBackgroundType(Style.BACKGROUND_IMAGE_ALIGNED);
        s.setBgImage(topfirst);
        s.setBgTransparency(255);
        s.setMargin(20, 0, 0, 0);
        s.setAlignment(Container.CENTER);
        s.setFgColor(0xffffff);
        lbltop.setEnabled(false);
        lbltop.setDisabledStyle(s);
        lbltop.setPreferredW(getWidth());
        lbltop.setPreferredH(45);
    }
    final void setConStyle(Container c){
        c.getStyle().setBgImage(backbtn);
        c.getStyle().setBgTransparency(255);
        c.setPreferredH(45);
        c.setPreferredW((int)(getWidth()*0.8));
        c.getStyle().setMargin(5, 0, getWidth()/10, 0);
    }
}
